package com.itheima.heimademo01.mapper;


import com.itheima.heimademo01.base.response.Result;
import com.itheima.heimademo01.pojo.dto.ArticleUpdateDTO;
import com.itheima.heimademo01.pojo.entity.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ArticleMapper {
    // 新增文章
    @Insert("insert into article(title,content,cover_img,state,category_id,create_user,create_time,update_time) values (#{article.title},#{article.content},#{article.coverImg},#{article.state},#{article.categoryId},#{article.createUser},#{article.createTime},#{article.updateTime})")
    void add(@Param("article") Article article);

    // 文章列表(条件分页)
    List<Article> list(@Param("userId") Integer userId, @Param("categoryId") Integer categoryId, @Param("state") String state);

    // 获取文章详情
    @Select("select * from article where id =#{id} ")
    Article detail(@Param("id") Integer id);

    // 更新文章
    @Update("update article set id=#{articleUpdateDTO.id},title=#{articleUpdateDTO.title},content=#{articleUpdateDTO.content},cover_img=#{articleUpdateDTO.coverImg}, state=#{articleUpdateDTO.state},category_id=#{articleUpdateDTO.categoryId} where id =#{articleUpdateDTO.id}")
    void update(@Param("articleUpdateDTO") ArticleUpdateDTO articleUpdateDTO);

    // 删除文章
    @Delete("delete from article where id = #{id}")
    void delete(@Param("id") Integer id);
}
